﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.IO;

namespace MultiResolutionService
{
	/// <summary>
	/// Summary description for ServerData
	/// </summary>
	[WebService(Namespace = "http://tempuri.org/")]
	[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
	[System.ComponentModel.ToolboxItem(false)]
	// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
	// [System.Web.Script.Services.ScriptService]
	public class ServerData : System.Web.Services.WebService
	{
		/// <summary>
		/// Zwraca liste plikow zawierajacych siatki progresywne danego algorytmu.
		/// </summary>
		/// <param name="algorithm">Algorytm.</param>
		/// <returns></returns>
		[WebMethod]
		public string[] ListOutFiles(string algorithm)
		{
			return GetFileNames(Context.Server.MapPath("ProgressiveOut/" + algorithm)).Distinct().ToArray();
		}

		/// <summary>
		/// Zwraca Liste plikow zawierajacych siatki oryginalne.
		/// </summary>
		[WebMethod]
		public string[] ListMeshFiles()
		{
			return GetFileNames(Context.Server.MapPath("Meshes"));
		}

		private string[] GetFileNames(string path)
		{
			string[] files = Directory.GetFiles(path);

			for (int i = 0; i < files.Count(); ++i)
			{
				files[i] = Path.GetFileNameWithoutExtension(files[i]);
			}

			return files;
		}
	}
}
